1 Effect of UPLTM-Based Decorrelation on Feature Discovery

1.0.1 Loading the libraries

library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)

op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)

1.1 Material and Methods

Data Source https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6960825/

Mohino-Herranz I, Gil-Pita R, Rosa-Zurera M, Seoane F. Activity Recognition Using Wearable Physiological Measurements: Selection of Features from a Comprehensive Literature Study. Sensors (Basel). 2019 Dec 13;19(24):0. doi: 10.3390/s19245524. PMID: 31847261; PMCID: PMC6960825.

1.2 The Data

Activitydata <- read.csv("~/GitHub/LatentBiomarkers/Data/ActivityData/data.txt", header=FALSE, stringsAsFactors=TRUE)
featNames <- read.table("~/GitHub/LatentBiomarkers/Data/ActivityData/Featurelabels.txt", quote="\"", comment.char="")
featNames <- as.character(t(featNames))
featNames <- str_replace_all(featNames,"\\(abs\\)","_A_")
featNames[duplicated(featNames)] <- paste(featNames[duplicated(featNames)],"D",sep="_")

rep_ID <- numeric(nrow(Activitydata))
ctr <- 1
for (ind in c(1:(nrow(Activitydata)-1)))
{
  rep_ID[ind] <- ctr
  if (Activitydata$V1[ind] != Activitydata$V1[ind+1]) ctr <- 0;
  ctr <- ctr + 1
}
rownames(Activitydata) <- paste(Activitydata$V1,rep_ID,sep="_")
colnames(Activitydata) <- c("ID",featNames,"class")
Activitydata$rep <- rep_ID
  
tb <- table(Activitydata$class)

classes <- c("Neu","Emo","Men","Phy")
names(classes) <- names(tb)
Activitydata$class <- classes[as.character(Activitydata$class)]
table(Activitydata$class)
#> 
#>  Emo  Men  Neu  Phy 
#> 1120 1120 1120 1120



ID_class <- paste(Activitydata$ID,Activitydata$class)
IDCLASS <- unique(ID_class)
theclass <- Activitydata$class[!duplicated(ID_class)]
theIDs <- Activitydata$ID[!duplicated(ID_class)]

ActivitydataAvg <- NULL
for (id in IDCLASS)
{
  ActivitydataAvg <- rbind(ActivitydataAvg,apply(Activitydata[ID_class==id,featNames],2,mean))
}
colnames(ActivitydataAvg) <- featNames
rownames(ActivitydataAvg) <- IDCLASS
ActivitydataAvg <- as.data.frame(ActivitydataAvg)
ActivitydataAvg$class <- theclass
ActivitydataAvg$ID <- theIDs

table(ActivitydataAvg$class)
#> 
#> Emo Men Neu Phy 
#>  40  40  40  40


ActivitydataAvg <- subset(ActivitydataAvg, class=="Men" | class=="Emo")

ActivitydataAvg$class <- 1*(ActivitydataAvg$class == "Men")
table(ActivitydataAvg$class)
#> 
#>  0  1 
#> 40 40

1.2.0.1 Standarize the names for the reporting

studyName <- "Activity"
dataframe <- ActivitydataAvg
outcome <- "class"

TopVariables <- 10
thro <- 0.80
cexheat = 0.15

1.3 Generaring the report

1.3.1 Libraries

Some libraries

library(psych)
library(whitening)
library("vioplot")
library("rpart")

1.3.2 Data specs

pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
rows col
80 534
pander::pander(table(dataframe[,outcome]))
0 1
40 40

varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]

largeSet <- length(varlist) > 1500 

1.3.3 Scaling the data

Scaling and removing near zero variance columns and highly co-linear(r>0.99999) columns


  ### Some global cleaning
  sdiszero <- apply(dataframe,2,sd) > 1.0e-16
  dataframe <- dataframe[,sdiszero]

  varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
  tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
  dataframe <- dataframe[,tokeep]

  varlist <- colnames(dataframe)
  varlist <- varlist[varlist != outcome]
  
  iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples



dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData

1.4 The heatmap of the data

numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000


if (!largeSet)
{

  hm <- heatMaps(data=dataframeScaled[1:numsub,],
                 Outcome=outcome,
                 Scale=TRUE,
                 hCluster = "row",
                 xlab="Feature",
                 ylab="Sample",
                 srtCol=45,
                 srtRow=45,
                 cexCol=cexheat,
                 cexRow=cexheat
                 )
  par(op)
}

1.4.0.1 Correlation Matrix of the Data

The heat map of the data


if (!largeSet)
{

  par(cex=0.6,cex.main=0.85,cex.axis=0.7)
  #cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
  cormat <- cor(dataframe[,varlist],method="pearson")
  cormat[is.na(cormat)] <- 0
  gplots::heatmap.2(abs(cormat),
                    trace = "none",
  #                  scale = "row",
                    mar = c(5,5),
                    col=rev(heat.colors(5)),
                    main = "Original Correlation",
                    cexRow = cexheat,
                    cexCol = cexheat,
                     srtCol=45,
                     srtRow=45,
                    key.title=NA,
                    key.xlab="|Pearson Correlation|",
                    xlab="Feature", ylab="Feature")
  diag(cormat) <- 0
  print(max(abs(cormat)))
}

[1] 1

1.5 The decorrelation


DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#> 
#>  ECG_PSD_median EDA_Filt1_prctile75_D EDA_Functionals_power_Fil12trimmean25 IT_LF_prctile25 EDA_Functionals_power_Originalskewness_D EDA_Original_kurtosis 
#>       ECG_original_mean        ECG_original_std ECG_original_trimmean25 
#>              0.12672176              0.78787879              0.12396694 
#>     ECG_original_median   ECG_original_skewness   ECG_original_kurtosis 
#>              0.18457300              0.06060606              0.05785124 
#> 
#>  Included: 363 , Uni p: 0.0004132231 , Base Size: 11 , Rcrit: 0.366515 
#> 
#> 
 1 <R=1.000,thr=0.950>, Top: 40< 1 >[Fa= 40 ]( 40 , 194 , 0 ),<|><>Tot Used: 234 , Added: 194 , Zero Std: 0 , Max Cor: 1.000
#> 
 2 <R=1.000,thr=0.950>, Top: 35< 3 >[Fa= 71 ]( 33 , 104 , 40 ),<|><>Tot Used: 262 , Added: 104 , Zero Std: 0 , Max Cor: 1.000
#> 
 3 <R=1.000,thr=0.950>, Top: 22< 2 >[Fa= 90 ]( 22 , 53 , 71 ),<|><>Tot Used: 277 , Added: 53 , Zero Std: 0 , Max Cor: 1.000
#> 
 4 <R=1.000,thr=0.950>, Top: 8< 1 >[Fa= 96 ]( 8 , 27 , 90 ),<|><>Tot Used: 277 , Added: 27 , Zero Std: 0 , Max Cor: 1.000
#> 
 5 <R=1.000,thr=0.950>, Top: 5< 4 >[Fa= 100 ]( 5 , 12 , 96 ),<|><>Tot Used: 277 , Added: 12 , Zero Std: 0 , Max Cor: 1.000
#> 
 6 <R=1.000,thr=0.950>, Top: 3< 4 >[Fa= 102 ]( 3 , 6 , 100 ),<|><>Tot Used: 277 , Added: 6 , Zero Std: 0 , Max Cor: 1.000
#> 
 7 <R=1.000,thr=0.950>, Top: 1< 4 >[Fa= 102 ]( 1 , 4 , 102 ),<|><>Tot Used: 277 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#> 
 8 <R=1.000,thr=0.950>, Top: 1< 4 >[Fa= 102 ]( 1 , 4 , 102 ),<|><>Tot Used: 277 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#> 
 9 <R=1.000,thr=0.950>, Top: 1< 4 >[Fa= 102 ]( 1 , 4 , 102 ),<|><>Tot Used: 277 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#> 
 10 <R=1.000,thr=0.950>, Top: 1< 3 >[Fa= 103 ]( 1 , 3 , 102 ),<|><>Tot Used: 277 , Added: 3 , Zero Std: 0 , Max Cor: 0.950
#> 
 11 <R=0.950,thr=0.900>, Top: 53< 1 >[Fa= 122 ]( 46 , 60 , 103 ),<|><>Tot Used: 296 , Added: 60 , Zero Std: 0 , Max Cor: 1.000
#> 
 12 <R=1.000,thr=0.950>, Top: 8< 1 >[Fa= 124 ]( 8 , 8 , 122 ),<|><>Tot Used: 296 , Added: 8 , Zero Std: 0 , Max Cor: 0.950
#> 
 13 <R=0.950,thr=0.900>, Top: 14< 1 >[Fa= 130 ]( 11 , 11 , 124 ),<|><>Tot Used: 301 , Added: 11 , Zero Std: 0 , Max Cor: 0.997
#> 
 14 <R=0.997,thr=0.950>, Top: 1< 1 >[Fa= 130 ]( 1 , 1 , 130 ),<|><>Tot Used: 301 , Added: 1 , Zero Std: 0 , Max Cor: 0.957
#> 
 15 <R=0.957,thr=0.950>, Top: 1< 1 >[Fa= 131 ]( 1 , 1 , 130 ),<|><>Tot Used: 301 , Added: 1 , Zero Std: 0 , Max Cor: 0.930
#> 
 16 <R=0.930,thr=0.900>, Top: 1< 1 >[Fa= 131 ]( 1 , 1 , 131 ),<|><>Tot Used: 301 , Added: 1 , Zero Std: 0 , Max Cor: 0.937
#> 
 17 <R=0.937,thr=0.900>, Top: 1< 1 >[Fa= 132 ]( 1 , 1 , 131 ),<|><>Tot Used: 301 , Added: 1 , Zero Std: 0 , Max Cor: 0.899
#> 
 18 <R=0.899,thr=0.800>, Top: 65< 4 >[Fa= 157 ]( 60 , 88 , 132 ),<|><>Tot Used: 323 , Added: 88 , Zero Std: 0 , Max Cor: 0.983
#> 
 19 <R=0.983,thr=0.950>, Top: 1< 1 >[Fa= 157 ]( 1 , 1 , 157 ),<|><>Tot Used: 323 , Added: 1 , Zero Std: 0 , Max Cor: 0.938
#> 
 20 <R=0.938,thr=0.900>, Top: 6< 1 >[Fa= 158 ]( 6 , 6 , 157 ),<|><>Tot Used: 323 , Added: 6 , Zero Std: 0 , Max Cor: 0.899
#> 
 21 <R=0.899,thr=0.800>, Top: 22< 2 >[Fa= 164 ]( 18 , 21 , 158 ),<|><>Tot Used: 328 , Added: 21 , Zero Std: 0 , Max Cor: 0.976
#> 
 22 <R=0.976,thr=0.950>, Top: 2< 1 >[Fa= 165 ]( 2 , 2 , 164 ),<|><>Tot Used: 328 , Added: 2 , Zero Std: 0 , Max Cor: 0.881
#> 
 23 <R=0.881,thr=0.800>, Top: 4< 1 >[Fa= 167 ]( 4 , 4 , 165 ),<|><>Tot Used: 329 , Added: 4 , Zero Std: 0 , Max Cor: 0.799
#> 
 24 <R=0.799,thr=0.800>
#> 
 [ 24 ], 0.9949082 Decor Dimension: 329 Nused: 329 . Cor to Base: 228 , ABase: 363 , Outcome Base: 0 
#> 
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]

pander::pander(sum(apply(dataframe[,varlist],2,var)))

2.43e+21

pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))

2.6e+14

pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))

0.0195

pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))

0.0632


varratio <- attr(DEdataframe,"VarRatio")

pander::pander(tail(varratio))
La_ECG_p_VFL_baseline La_IT_CCV_LF La_IT_BRV_prctile25 La_IT_BRV_min La_IT_BRV_max La_IT_BRV_prctile75
9.21e-14 1.05e-24 3.86e-27 4.73e-31 2.5e-31 5.81e-32

1.5.1 The decorrelation matrix


if (!largeSet)
{

  par(cex=0.6,cex.main=0.85,cex.axis=0.7)
  
  UPLTM <- attr(DEdataframe,"UPLTM")
  
  gplots::heatmap.2(1.0*(abs(UPLTM)>0),
                    trace = "none",
                    mar = c(5,5),
                    col=rev(heat.colors(5)),
                    main = "Decorrelation matrix",
                    cexRow = cexheat,
                    cexCol = cexheat,
                   srtCol=45,
                   srtRow=45,
                    key.title=NA,
                    key.xlab="|Beta|>0",
                    xlab="Output Feature", ylab="Input Feature")
  
  par(op)
  
  
  
}

1.5.2 Formulas Network

Displaying the features associations

par(op)


#if ((ncol(dataframe) < 1000) && (ncol(dataframe) > 10))
#{

#  DEdataframeB <- ILAA(dataframe,verbose=TRUE,thr=thro,bootstrap=30)

  transform <- attr(DEdataframe,"UPLTM") != 0
  tnames <- colnames(transform)
  colnames(transform) <- str_remove_all(colnames(transform),"La_")
  transform <- abs(transform*cor(dataframe[,rownames(transform)])) # The weights are proportional to the observed correlation
  
  
  VertexSize <- attr(DEdataframe,"fscore") # The size depends on the variable independence relevance (fscore)
  names(VertexSize) <- str_remove_all(names(VertexSize),"La_")
  VertexSize <- 10*(VertexSize-min(VertexSize))/(max(VertexSize)-min(VertexSize)) # Normalization

  VertexSize <- VertexSize[rownames(transform)]
  rsum <- apply(1*(transform !=0),1,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
  csum <- apply(1*(transform !=0),2,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
  
  ntop <- min(10,length(rsum))


  topfeatures <- unique(c(names(rsum[order(-rsum)])[1:ntop],names(csum[order(-csum)])[1:ntop]))
  rtrans <- transform[topfeatures,]
  csum <- (apply(1*(rtrans !=0),2,sum) > 1)
  rtrans <- rtrans[,csum]
  topfeatures <- unique(c(topfeatures,colnames(rtrans)))
  print(ncol(transform))
#> [1] 329
  transform <- transform[topfeatures,topfeatures]
  print(ncol(transform))
#> [1] 68
  if (ncol(transform)>100)
  {
    csum <- (apply(1*(transform !=0),2,sum) > 1) & (apply(1*(transform !=0),1,sum) > 1)
    transform <- transform[csum,csum]
    print(ncol(transform))
  }

    if (ncol(transform) < 150)
    {

      gplots::heatmap.2(transform,
                        trace = "none",
                        mar = c(5,5),
                        col=rev(heat.colors(5)),
                        main = "Red Decorrelation matrix",
                        cexRow = cexheat,
                        cexCol = cexheat,
                       srtCol=45,
                       srtRow=45,
                        key.title=NA,
                        key.xlab="|Beta|>0",
                        xlab="Output Feature", ylab="Input Feature")
  
      par(op)
      VertexSize <- VertexSize[colnames(transform)]
      gr <- graph_from_adjacency_matrix(transform,mode = "directed",diag = FALSE,weighted=TRUE)
      gr$layout <- layout_with_fr
      
      fc <- cluster_optimal(gr)
      plot(fc, gr,
           edge.width = 2*E(gr)$weight,
           vertex.size=VertexSize,
           edge.arrow.size=0.5,
           edge.arrow.width=0.5,
           vertex.label.cex=(0.15+0.05*VertexSize),
           vertex.label.dist=0.5 + 0.05*VertexSize,
           main="Top Feature Association")
      
    }


par(op)

1.6 The heatmap of the decorrelated data

if (!largeSet)
{

  hm <- heatMaps(data=DEdataframe[1:numsub,],
                 Outcome=outcome,
                 Scale=TRUE,
                 hCluster = "row",
                 cexRow = cexheat,
                 cexCol = cexheat,
                 srtCol=45,
                 srtRow=45,
                 xlab="Feature",
                 ylab="Sample")
  par(op)
}

1.7 The correlation matrix after decorrelation

if (!largeSet)
{

  cormat <- cor(DEdataframe[,varlistc],method="pearson")
  cormat[is.na(cormat)] <- 0
  
  gplots::heatmap.2(abs(cormat),
                    trace = "none",
                    mar = c(5,5),
                    col=rev(heat.colors(5)),
                    main = "Correlation after ILAA",
                    cexRow = cexheat,
                    cexCol = cexheat,
                     srtCol=45,
                     srtRow=45,
                    key.title=NA,
                    key.xlab="|Pearson Correlation|",
                    xlab="Feature", ylab="Feature")
  
  par(op)
  diag(cormat) <- 0
  print(max(abs(cormat)))
}

[1] 1

1.8 U-MAP Visualization of features

1.8.1 The UMAP on Raw Data


  classes <- unique(dataframe[1:numsub,outcome])
  raincolors <- rainbow(length(classes))
  names(raincolors) <- classes
  topvars <- univariate_BinEnsemble(dataframe,outcome)
  lso <- LASSO_MIN(formula(paste(outcome,"~.")),dataframe,family="binomial")
  topvars <- unique(c(names(topvars),lso$selectedfeatures))
  pander::pander(head(topvars))

IT_MF_baseline, ECG_hrv_prctile25, ECG_hrv_mean, _ECG_hrv_geomean_A__, ECG_hrv_prctile75 and EDA_processed_mean_D

#  names(topvars)
#if (nrow(dataframe) < 1000)
#{
  datasetframe.umap = umap(scale(dataframe[1:numsub,topvars]),n_components=2)
#  datasetframe.umap = umap(dataframe[1:numsub,varlist],n_components=2)
  plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
  text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])

#}

1.8.2 The decorralted UMAP

  varlistcV <- names(varratio[varratio >= 0.025])
  topvars <- univariate_BinEnsemble(DEdataframe[,varlistcV],outcome)
  lso <- LASSO_MIN(formula(paste(outcome,"~.")),DEdataframe,family="binomial")
  topvars <- unique(c(names(topvars),lso$selectedfeatures))
  pander::pander(head(topvars))

La_ECG_RR_window_baseline, La_IT_BRV_baseline, La_EDA_processed_mad_D, La_EDA_Original_baseline_D, IT_p_Total_baseline and La_EDA_processed_trimmean25_D


  varlistcV <- varlistcV[varlistcV != outcome]
  
#  DEdataframe[,outcome] <- as.numeric(DEdataframe[,outcome])
#if (nrow(dataframe) < 1000)
#{
  datasetframe.umap = umap(scale(DEdataframe[1:numsub,topvars]),n_components=2)
#  datasetframe.umap = umap(DEdataframe[1:numsub,varlistcV],n_components=2)
  plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After ILAA",t='n')
  text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])

#}

1.9 Univariate Analysis

1.9.1 Univariate



univarRAW <- uniRankVar(varlist,
               paste(outcome,"~1"),
               outcome,
               dataframe,
               rankingTest="AUC")

100 : ECG_p_LF_mean 200 : IT_CCV_LF 300 : EDA_Original_mad_D




univarDe <- uniRankVar(varlistc,
               paste(outcome,"~1"),
               outcome,
               DEdataframe,
               rankingTest="AUC",
               )

100 : La_ECG_p_LF_mean 200 : La_IT_CCV_LF 300 : La_EDA_Original_mad_D

1.9.2 Final Table


univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")

##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
  caseMean caseStd controlMean controlStd controlKSP ROCAUC
ECG_hrv_prctile75 -2.719 8.9741 -5.8408 10.9387 0.00378 0.731
ECG_hrv_geomean_A_ 10.370 8.0477 13.8743 7.8682 0.00822 0.727
IT_LF_baseline_D 43.569 25.1600 26.4345 15.3449 0.61672 0.721
IT_p_Total_baseline 51.974 29.4230 31.5389 17.9800 0.71076 0.721
IT_VLF_baseline 57.578 32.3488 34.9418 19.7865 0.75500 0.720
ECG_hrv_prctile25 -12.471 7.7963 -16.6349 6.7770 0.20654 0.719
IT_PSD_baseline 0.059 0.0376 0.0358 0.0228 0.21000 0.715
ECG_hrv_mean -7.294 5.4920 -11.0369 6.0390 0.33833 0.714
IT_HF_baseline 3.308 3.5341 2.0033 2.1158 0.00564 0.713
ECG_hrv_trimmean25 -7.619 6.1613 -11.3761 6.3193 0.35724 0.711


topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]


pander::pander(finalTable)
  caseMean caseStd controlMean controlStd controlKSP ROCAUC
La_ECG_RR_window_baseline 20.516 15.679 9.022 13.793 0.11840 0.784
La_EDA_Original_mad_D -7.578 10.562 1.170 9.564 0.01215 0.776
La_EDA_processed_mad_D 17.446 19.540 0.556 14.531 0.08373 0.766
La_IT_BRV_baseline -3.930 2.265 -2.114 1.544 0.80056 0.756
La_ECG_hrv_mean -1.592 0.433 -1.960 0.586 0.41819 0.741
La_EDA_Original_baseline_D -589.265 1714.012 639.035 1149.458 0.01696 0.739
La_EDA_processed_std_D 18.628 35.322 -12.898 34.532 0.00649 0.730
La_ECG_HR_min_div_baseline 7.076 5.360 9.575 5.454 0.14465 0.727
La_EDA_processed_trimmean25_D 0.999 2.270 -0.379 1.094 0.15207 0.721
IT_p_Total_baseline 51.974 29.423 31.539 17.980 0.71076 0.721

dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")


pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
mean total fraction
3.23 296 0.811

theCharformulas <- attr(dc,"LatentCharFormulas")


finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])


orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]

Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores")

finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
  DecorFormula caseMean caseStd controlMean controlStd controlKSP ROCAUC RAWAUC fscores
La_ECG_RR_window_baseline - (0.875)ECG_RR_window_prctile75 + ECG_RR_window_baseline 20.516 1.57e+01 9.0216 1.38e+01 0.11840 0.784 0.522 0
La_EDA_Original_mad_D - (0.831)EDA_Original_std_D + EDA_Original_mad_D -7.578 1.06e+01 1.1699 9.56e+00 0.01215 0.776 0.507 0
La_EDA_processed_mad_D - (0.139)EDA_Original_std_D + EDA_processed_mad_D 17.446 1.95e+01 0.5558 1.45e+01 0.08373 0.766 0.604 -1
La_IT_BRV_baseline - (0.588)IT_BRV_mean + IT_BRV_baseline -3.930 2.27e+00 -2.1142 1.54e+00 0.80056 0.756 0.642 -1
La_ECG_hrv_mean - (0.694)ECG_HR_min_div_mean + (0.681)ECG_HR_min_div_trimmean25 + ECG_hrv_mean - (0.916)ECG_hrv_trimmean25 -1.592 4.33e-01 -1.9604 5.86e-01 0.41819 0.741 0.714 -1
La_EDA_Original_baseline_D + EDA_Original_baseline_D - (0.877)EDA_Filt1_prctile75_D -589.265 1.71e+03 639.0354 1.15e+03 0.01696 0.739 0.504 0
ECG_hrv_prctile75 NA -2.719 8.97e+00 -5.8408 1.09e+01 0.00378 0.731 0.731 NA
La_EDA_processed_std_D - (0.295)EDA_Original_std_D + EDA_processed_std_D 18.628 3.53e+01 -12.8982 3.45e+01 0.00649 0.730 0.581 1
La_ECG_HR_min_div_baseline - (0.888)ECG_HR_min_div_mean + ECG_HR_min_div_baseline 7.076 5.36e+00 9.5745 5.45e+00 0.14465 0.727 0.518 -1
ECG_hrv_geomean_A_ NA 10.370 8.05e+00 13.8743 7.87e+00 0.00822 0.727 0.727 NA
La_EDA_processed_trimmean25_D + EDA_processed_trimmean25_D - (0.652)EDA_processed_median_D 0.999 2.27e+00 -0.3787 1.09e+00 0.15207 0.721 0.582 0
IT_LF_baseline_D NA 43.569 2.52e+01 26.4345 1.53e+01 0.61672 0.721 0.721 NA
IT_p_Total_baseline NA 51.974 2.94e+01 31.5389 1.80e+01 0.71076 0.721 0.721 4
IT_p_Total_baseline1 NA 51.974 2.94e+01 31.5389 1.80e+01 0.71076 0.721 NA NA
IT_VLF_baseline NA 57.578 3.23e+01 34.9418 1.98e+01 0.75500 0.720 0.720 NA
ECG_hrv_prctile25 NA -12.471 7.80e+00 -16.6349 6.78e+00 0.20654 0.719 0.719 NA
IT_PSD_baseline NA 0.059 3.76e-02 0.0358 2.28e-02 0.21000 0.715 0.715 NA
ECG_hrv_mean NA -7.294 5.49e+00 -11.0369 6.04e+00 0.33833 0.714 0.714 NA
IT_HF_baseline NA 3.308 3.53e+00 2.0033 2.12e+00 0.00564 0.713 0.713 0
ECG_hrv_trimmean25 NA -7.619 6.16e+00 -11.3761 6.32e+00 0.35724 0.711 0.711 4

1.10 Comparing ILAA vs PCA vs EFA

1.10.1 PCA

featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE)   #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous]) 
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)

#pander::pander(pc$rotation)


PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])


  gplots::heatmap.2(abs(PCACor),
                    trace = "none",
  #                  scale = "row",
                    mar = c(5,5),
                    col=rev(heat.colors(5)),
                    main = "PCA Correlation",
                    cexRow = 0.5,
                    cexCol = 0.5,
                     srtCol=45,
                     srtRow= -45,
                    key.title=NA,
                    key.xlab="Pearson Correlation",
                    xlab="Feature", ylab="Feature")

1.10.2 EFA


EFAdataframe <- dataframeScaled

if (length(iscontinous) < 2000)
{
  topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)/2)
  if (topred < 2) topred <- 2
  
  uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE)  # EFA analysis
  predEFA <- predict(uls,dataframeScaled[,iscontinous])
  EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
  colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous]) 


  
  EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
  
  
    gplots::heatmap.2(abs(EFACor),
                      trace = "none",
    #                  scale = "row",
                      mar = c(5,5),
                      col=rev(heat.colors(5)),
                      main = "EFA Correlation",
                      cexRow = 0.5,
                      cexCol = 0.5,
                       srtCol=45,
                       srtRow= -45,
                      key.title=NA,
                      key.xlab="Pearson Correlation",
                      xlab="Feature", ylab="Feature")
}

1.11 Effect on CAR modeling

par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")

  ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
  if (length(unique(pr))>1)
  {
    plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
    text(rawmodel, use.n = TRUE,cex=0.75)
    ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
  }


pander::pander(table(dataframe[,outcome],pr))
  0 1
0 38 2
1 7 33
pander::pander(ptab$detail[c(5,3,4,6),])
  statistic est lower upper
5 diag.ac 0.887 0.797 0.947
3 se 0.825 0.672 0.927
4 sp 0.950 0.831 0.994
6 diag.or 89.571 17.389 461.391

par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe[,c(outcome,varlistcV)],control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")

  ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
  if (length(unique(pr))>1)
  {
    plot(IDeAmodel,main="ILAA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
    text(IDeAmodel, use.n = TRUE,cex=0.75)
    ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
  }

pander::pander(table(DEdataframe[,outcome],pr))
  0 1
0 36 4
1 8 32
pander::pander(ptab$detail[c(5,3,4,6),])
  statistic est lower upper
5 diag.ac 0.85 0.753 0.920
3 se 0.80 0.644 0.909
4 sp 0.90 0.763 0.972
6 diag.or 36.00 9.897 130.943

par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
  plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
  text(PCAmodel, use.n = TRUE,cex=0.75)
  ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}

pander::pander(table(PCAdataframe[,outcome],pr))
  0 1
0 23 17
1 0 40
pander::pander(ptab$detail[c(5,3,4,6),])
  statistic est lower upper
5 diag.ac 0.787 0.682 0.871
3 se 1.000 0.912 1.000
4 sp 0.575 0.409 0.730
6 diag.or Inf NA Inf


par(op)

1.11.1 EFA


  EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
  EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
  pr <- predict(EFAmodel,EFAdataframe,type = "class")
  
  ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
  if (length(unique(pr))>1)
  {
    plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
    text(EFAmodel, use.n = TRUE,cex=0.75)
    ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
  }


  pander::pander(table(EFAdataframe[,outcome],pr))
  0 1
0 34 6
1 9 31
  pander::pander(ptab$detail[c(5,3,4,6),])
  statistic est lower upper
5 diag.ac 0.812 0.710 0.891
3 se 0.775 0.615 0.892
4 sp 0.850 0.702 0.943
6 diag.or 19.519 6.230 61.147
  par(op)